﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Taskbar;

namespace WinBg
{
    public partial class Main : GlassForm
    {

        #region Variables
        //private string UserHomePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "WinBg");
        public static string HiddenDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WinBg");
        private static string UserBgPath = Path.Combine(HiddenDataPath, "Bg");
        public const string WebSite_Name = "http://www.testwinbg.byethost32.com/";
        //public const string WebSite_Name = "http://localhost/winbg/";
        ImageInfo Imageinfo = new ImageInfo();
        CheckBox[] Catergory;
        Timer time = new Timer();
        DownloadImage DownImage;
        HttpRequest Http_Request = new HttpRequest(WebSite_Name);
        Wallpaper wallpaper = new Wallpaper();
        private int NumberofPreview = 1;
        TimeSpan Remaining;
        ThumbnailToolBarButton NewbackgroundButton;
        bool FormCollapseHeight = false;
        bool FormIsCollapseWidth = false;
        bool UpdateOpen = true;
        bool FormCollapseWidthHeight = true;
        int Voteing = 0;
        Size orignal;
        enum Resizingtypes { Width, Height };
        bool RealClose;
        bool ValidApply = false;
        string ImagesPath = "Images/";
        //string IconsPath = "../Resources/Icons/";
        #endregion

        public Main()
        {
            #region UIHandlers
            InitializeComponent();
            CreateMyOwnPath();
            DeleteUpdateFile();

            orignal = this.Size;

            //this.WindowState = FormWindowState.Minimized;

            Remaining = new TimeSpan(0, 0, (int)time.CheckDateTime(DateTime.Now));

            lbl_Daytimer.Text = Remaining.ToString();

            DayTimer.Enabled = true;


            AeroGlassCompositionChanged += new EventHandler<AeroGlassCompositionChangedEventArgs>(Form1_AeroGlassCompositionChanged);


            if (AeroGlassCompositionEnabled)
            {
                ExcludeControlFromAeroGlass(panel1);
            }
            else
            {
                this.BackColor = System.Drawing.Color.White;
            }

            AeroGlassCompositionEnabled = true;

            CheckBoxesCreate();

            //UpdateState();
            this.Hide();
            #endregion
            #region FunctionsHandler
            CheckConnectionState();
            Imageinfo.Name = "";
            Imageinfo.Categories = "all";
            picbox_PreviewImage.ImageLocation = wallpaper.GetWallpaper();
            #endregion
        }
        private void CheckBoxesCreate()
        {
            if (File.Exists(Main.HiddenDataPath + "\\AllcategoriesClient.xml"))
            {
                CreateCheckBoxes();
            }
            else
            {
                if (InternetConnections.IsConnectedToInternet() == true)
                {
                    Initconnection.GetXML();
                    CreateCheckBoxes();
                }
                else
                {
                    XMLHandler.WriteAllCatigories();
                    CreateCheckBoxes();
                }
            }
        }
        void Form1_AeroGlassCompositionChanged(object sender, AeroGlassCompositionChangedEventArgs e)
        {
            if (e.GlassAvailable)
            {
                Invalidate();
            }
            else
            {
                this.BackColor = System.Drawing.Color.White;
            }
        }

        private void compositionEnabled_CheckedChanged(object sender, EventArgs e)
        {
            // Toggles the desktop composition mode.
            AeroGlassCompositionEnabled = true;
        }

        private void DayTimer_Tick(object sender, EventArgs e)
        {
            Remaining = Remaining - new TimeSpan(10000000);
            lbl_Daytimer.Text = Remaining.ToString();
        }

        private void toolStripMenuItem_Show_Click(object sender, EventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.ShowInTaskbar = true;
            // ExcludeControlFromAeroGlass(panel1);  
        }
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            RealClose = true;
            this.Close();
        }

        private void notifyIcon_WinBg_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            // ExcludeControlFromAeroGlass(panel1);
            Invalidate();
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.ShowInTaskbar = true;
        }
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            NewbackgroundButton = new ThumbnailToolBarButton(Properties.Resources.EZ_Play, "Get New Background");
            NewbackgroundButton.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(NewbackgroundButton_Click);
            TaskbarManager.Instance.ThumbnailToolBars.AddButtons(this.Handle, NewbackgroundButton);
        }
        private void NewbackgroundButton_Click(object sender, ThumbnailButtonClickedEventArgs e)
        {

            if (InternetConnections.IsConnectedToInternet())
            {
                //CreateMyOwnPath();          //Check and Create my Own Path
                string Categories = GetCategoriesChecked();
                if (Categories != "")
                {
                    //RequestNewBackground("0", Categories);
                    if (NumberofPreview <= 3)
                    {
                        //PreviewNewBackGround(GetImageName(wallpaper.GetWallpaper()), Categories);
                        PreviewNewBackgroundWorker.RunWorkerAsync();
                        NumberofPreview++;
                    }
                    else
                    {
                        MessageBox.Show("You Reach Maxim Number of Preview Request !!!");
                    }
                }
                else
                    MessageBox.Show("You Should Select at lest One Categories");
            }
            else
                MessageBox.Show("Check Your Internet Connections");
        }
        private void PauseButton_Click(object sender, ThumbnailButtonClickedEventArgs e)
        {
            MessageBox.Show("Not Done");
        }
        private void lbl_Expand_Click(object sender, EventArgs e)
        {
            if (FormIsCollapseWidth == false)
            {
                Grow_Form(Resizingtypes.Width);
                this.picbox_expand.Image = Image.FromFile(@ImagesPath + "collapseIcon.png");

            }
            else
            {
                Shrink_Form(Resizingtypes.Width);
                this.picbox_expand.Image = Image.FromFile(@ImagesPath + "expandIcon.png");

            }

        }
        private void lbl_Vote_Click(object sender, EventArgs e)
        {
            if (!UpdateOpen)
            {
                picbox_Star1.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
                picbox_Star2.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
                picbox_Star3.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
                picbox_Star4.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
                picbox_Star5.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            }
            if (FormIsCollapseWidth == true)
            {
                Grow_Form(Resizingtypes.Width);
            }
        }
        private void picbox_Star1_Click(object sender, EventArgs e)
        {
            picbox_Star1.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            Voteing = 1;
            picbox_Star2.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star3.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star4.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star5.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
        }
        private void picbox_Star2_Click(object sender, EventArgs e)
        {
            picbox_Star1.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star2.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            Voteing = 2;
            picbox_Star3.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star4.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star5.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
        }
        private void picbox_Star3_Click(object sender, EventArgs e)
        {
            picbox_Star1.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star2.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star3.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            Voteing = 3;
            picbox_Star4.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star5.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
        }
        private void picbox_Star4_Click(object sender, EventArgs e)
        {

            picbox_Star1.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star2.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star3.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star4.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            Voteing = 4;
            picbox_Star5.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
        }
        private void picbox_Star5_Click(object sender, EventArgs e)
        {
            picbox_Star1.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star2.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star3.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star4.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            picbox_Star5.Image = Image.FromFile(@ImagesPath + "FilledStar.png");
            Voteing = 5;
        }
        private void lbl_Submit_Click(object sender, EventArgs e)
        {
            picbox_Star1.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star2.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star3.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star4.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");
            picbox_Star5.Image = Image.FromFile(@ImagesPath + "EmptyStar.png");

            panel2.Visible = true;
            try
            {
                string PostData = string.Format("Name={0}&Category={1}&Vote={2}", GetImageNameFromUrl(wallpaper.GetWallpaper()), Imageinfo.Categories, Voteing);
                Http_Request.Voting(PostData);
            }
            catch (Exception EX)
            {
                ErrorReport.AddError(this.ToString(), "lbl_Vote_Click", EX.Message);
            }
            Voteing = 0;
        }
        private void lbl_Feedback_Click(object sender, EventArgs e)
        {
            this.Hide();
            FeedbackForm Previewform = new FeedbackForm();
            Previewform.ShowDialog();
            this.Show();
        }
        private void Grow_Form(Resizingtypes Type)
        {
            if (Type == Resizingtypes.Width)
            {
                int FormWidth = this.Width;
                for (int i = 0; i < orignal.Width - 325; i++)
                {
                    int newWidth = FormWidth + i;
                    this.Width = newWidth;
                }
                FormIsCollapseWidth = true;
            }
            else
            {
                int FormHeight = this.Height;
                for (int i = 0; i < orignal.Height - 470; i++)
                {
                    int newheight = FormHeight + i;
                    this.Height = newheight;
                }
                FormCollapseHeight = true;
            }
        }
        private void Shrink_Form(Resizingtypes Type)
        {

            if (Type == Resizingtypes.Width)
            {
                int FormWidth = this.Width;
                for (int i = 0; i < orignal.Width - 325; i++)
                {
                    int newWidth = FormWidth - i;
                    this.Width = newWidth;
                }
                FormIsCollapseWidth = false;
            }
            else
            {
                int FormHeight = this.Height;
                for (int i = 0; i < orignal.Height - 470; i++)
                {
                    int newheight = FormHeight - i;
                    this.Height = newheight;
                }
                FormCollapseHeight = false;
            }

        }
        private void btn_NextBackGround_Click(object sender, EventArgs e)
        {
            this.Hide();
            PreviewForm Previewform = new PreviewForm();
            Previewform.ShowDialog();
            this.Show();
        }
        private void UpdateState()
        {

            UpdateOpen = true;
            picbox_Updates.Visible = true;
            lbl_UpdateState.Visible = true;
            if (Updates.CheckUpdate())
            {
                Grow_Form(Resizingtypes.Height);
                lbl_UpdateState.Text = string.Format("New update available ({0}) ", Updates.GetVersion());
                picbox_Updates.Image = Image.FromFile(@ImagesPath + "Attention.gif");
                lbl_Download.Visible = true;
                lbl_Later.Visible = true;
            }

        }
        private void lbl_Download_Click(object sender, EventArgs e)
        {
            lbl_UpdateState.Text = "Downloading...";
            picbox_Updates.Image = Image.FromFile(@ImagesPath + "DownloadingUpdates.gif");
            Updates.GetUpdate();
            lbl_Download.Visible = false;
            lbl_Later.Visible = false;
        }
        private void lbl_Later_Click(object sender, EventArgs e)
        {
            Shrink_Form(Resizingtypes.Height);
            picbox_Updates.Visible = false;
            lbl_UpdateState.Visible = false;
            lbl_Download.Visible = false;
            lbl_Later.Visible = false;
            //UpdateOpen = false;
        }
        private void lbl_OK_Click(object sender, EventArgs e)
        {

            Shrink_Form(Resizingtypes.Height);
            picbox_Updates.Visible = false;
            lbl_UpdateState.Visible = false;
            lbl_Download.Visible = false;
            lbl_Later.Visible = false;
            //UpdateOpen = false;
        }

        private void CheckTimer_Tick(object sender, EventArgs e)
        {
            if (time.CheckDateTime(DateTime.Now) <= 0)  //Check if time to change BG
            {
                string Categories = GetCategoriesChecked();
                if (InternetConnections.IsConnectedToInternet() && !RequestNewBackgroundWorker.IsBusy)     //Check if there is Internet Connection
                {
                    try
                    {
                        if(Categories != "")
                            RequestNewBackgroundWorker.RunWorkerAsync();
                        else
                            MessageBox.Show("You Should Select at lest One Categories");
                    }
                    catch (Exception EX)
                    {
                        ErrorReport.AddError(this.ToString(), "CheckTimer_Tick", EX.Message);
                    }
                }
            }
            CheckConnectionState();
        }
        private void RequestNewBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            picbox_LoadImage.Refresh();
            RequestNewBackground(GetImageNameFromUrl(wallpaper.GetWallpaper()), GetCategoriesChecked());
        }
        private void RequestNewBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            time.UpdateTimeFileByHours(24);   //Add 24 hours to time
            Remaining = new TimeSpan(0, 0, (int)time.CheckDateTime(DateTime.Now));
            //notifyIcon_WinBg.ShowBalloonTip(3000, "New background", "There is a new Background", ToolTipIcon.Info);
        }
        private void PreviewNewBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            PreviewNewBackGround(GetImageNameFromUrl(wallpaper.GetWallpaper()), GetCategoriesChecked());
        }
        private void PreviewNewBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            picbox_LoadImage.Visible = false;
            ValidApply = true;
        }
        private void picbox_Next_Click(object sender, EventArgs e)
        {

            if (InternetConnections.IsConnectedToInternet() && !PreviewNewBackgroundWorker.IsBusy)
            {
                //CreateMyOwnPath();          //Check and Create my Own Path
                string Categories = GetCategoriesChecked();
                if (Categories != "")
                {
                    //RequestNewBackground("0", Categories);
                    if (NumberofPreview <= 3)
                    {
                        //PreviewNewBackGround(GetImageName(wallpaper.GetWallpaper()), Categories);
                        PreviewNewBackgroundWorker.RunWorkerAsync();
                        NumberofPreview++;
                        picbox_LoadImage.Visible = true;
                    }
                    else
                    {
                        MessageBox.Show("You have Reached Maximum Number of Preview Request !!!");
                    }
                }
                else
                    MessageBox.Show("You Should Select at lest One Categories");
            }
            else
                MessageBox.Show("Check Your Internet Connections");
        }
        private void picbox_Apply_Click(object sender, EventArgs e)
        {
            if (ValidApply)
            {
                ApplayNewBackGround(Imageinfo.TempPath);
                time.UpdateTimeFileByHours(24);   //Add 24 hours to time
                Remaining = new TimeSpan(0, 0, (int)time.CheckDateTime(DateTime.Now));
                panel2.Visible = false;
                ValidApply = false;
            }
            else
                MessageBox.Show("Nothing to Apply");
        }
        private void lbl_Visitus_Click(object sender, EventArgs e)
        {
            lbl_Visitus.LinkVisited = true;
            System.Diagnostics.Process.Start("https://www.facebook.com/WinBg");
        }
        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!RealClose)
            {
                e.Cancel = true;
                //WindowState = FormWindowState.Minimized;
                this.Hide();
            }
            else
            {
                Application.Exit();
            }
        }


        #region Help Methods
        private void RequestNewBackground(string CurrentBg_Name, string Categories)
        {
            NumberofPreview = 1;
            string CurrentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            string PostData = string.Format("Name={0}&Categories={1}&Version={2}", CurrentBg_Name, Categories, CurrentVersion);
            string Link = Http_Request.RequestNewBg(PostData);
            Imageinfo.Name = GetImageNameFromUrl(Link);
            Imageinfo.Categories = GetCategoriesNameFromUrl(Link);
            Imageinfo.Path = UserBgPath + "\\" + Imageinfo.Name;
            DownloadImage(Link, Imageinfo.Path);
            SetWallpaper(Imageinfo.Path);
            TryToDelete(Imageinfo.Path);
            SendErrorReport();
            picbox_PreviewImage.ImageLocation = Imageinfo.Path;
        }
        private void PreviewNewBackGround(string CurrentBg_Name, string Categories)
        {
            string CurrentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            string PostData = string.Format("Name={0}&Categories={1}&Version={2}", CurrentBg_Name, Categories, CurrentVersion);
            string Link = Http_Request.RequestNewBg(PostData);
            Imageinfo.TempName = GetImageNameFromUrl(Link);
            Imageinfo.TempCategories = GetCategoriesNameFromUrl(Link);
            Imageinfo.TempPath = UserBgPath + "\\" + Imageinfo.TempName;
            DownloadImage(Link, Imageinfo.TempPath);
            picbox_PreviewImage.ImageLocation = Imageinfo.TempPath;
        }
        private void ApplayNewBackGround(string ImagePath)
        {
            SetWallpaper(ImagePath);
            TryToDelete(ImagePath);
            SendErrorReport();
        }
        private string GetCategoriesChecked()
        {
            string Cat = string.Empty;
            string Split = "|";
            if (checkbox_All.Checked)
                Cat += "All" + Split;
            for (int i = 1; i < Catergory.Length; i++)
            {
                if (Catergory[i].Checked)
                    Cat += Catergory[i].Text.ToLower() + Split;
            }
            if (Cat != "")
            {
                Cat = Cat.Substring(0, Cat.Length - 1);
            }
            return Cat;
        }
        private void CreateMyOwnPath()
        {
            try
            {
                System.IO.Directory.CreateDirectory(HiddenDataPath);
                System.IO.Directory.CreateDirectory(UserBgPath);

            }
            catch (Exception EX)
            {
                ErrorReport.AddError(this.ToString(), "CreateMyOwnPath", EX.Message);
            }
        }
        public string GetImageNameFromUrl(string Link)
        {
            string Name = string.Empty;
            for (int i = Link.Length - 1; i >= 0; i--)
            {
                if (Link[i] != '/' && Link[i] != '\\')
                {
                    Name += Link[i];
                }
                else
                    break;
            }
            string Temp = string.Empty;
            for (int i = Name.Length - 1; i >= 0; i--)
            {
                Temp += Name[i];
            }
            return Temp;
        }
        private string GetCategoriesNameFromUrl(string Link)
        {
            int Index = Link.LastIndexOf('/');
            string Temp = string.Empty;
            string Name = string.Empty;
            if (Index != -1)
            {
                for (int i = Index - 1; i >= 0; i--)
                {
                    if (Link[i] != '/')
                    {
                        Temp += Link[i];
                    }
                    else
                        break;
                }
                for (int i = Temp.Length - 1; i >= 0; i--)
                {
                    Name += Temp[i];
                }
            }
            return Name;
        }
        private void DownloadImage(string Link, string Destination)
        {
            DownImage = new DownloadImage(Link);
            //DownImage.Download();
            DownImage.DownloadImageFromUrl();
            //while (th.IsAlive) { }
            DownImage.SaveImage(Destination, ImageFormat.Jpeg);  //@"C:\Users\AhmedMhana\Documents\WinBg\"
        }
        private void SetWallpaper(string FilePath)
        {
            wallpaper = new Wallpaper(FilePath);
            wallpaper.SetWallpaper();
            wallpaper.SetStyle("Fill");
        }
        private bool TryToDelete(string file)
        {
            try
            {
                string[] FilePaths = Directory.GetFiles(UserBgPath);
                foreach (string Text in FilePaths)
                {
                    if (Text != file)
                        File.Delete(Text);
                }
                return true;
            }
            catch (Exception Ex)
            {
                ErrorReport.AddError(this.ToString(), "TryToDelete", Ex.Message);
                return false;
            }
        }
        private void ClearFileContent(string FilePath)
        {
            StreamWriter streamWriter = null;
            try
            {
                streamWriter = new StreamWriter(FilePath);
                streamWriter.WriteLine("");
                streamWriter.Close();
            }
            catch (Exception EX)
            {
                ErrorReport.AddError(this.ToString(), "ClearFileContent", EX.Message);
            }
            finally
            {
                if (streamWriter != null)
                    streamWriter.Close();
            }
        }
        private void SendErrorReport()
        {
            string ErrorReportFile = string.Empty;
            ErrorReport.FileExists();
            StreamReader streamReader = null;
            try
            {
                //Read ErrorReport File
                string FilePath = HiddenDataPath + "\\ErrorReport";
                streamReader = new StreamReader(FilePath);
                ErrorReportFile = streamReader.ReadToEnd();
                streamReader.Close();
                if (ErrorReportFile != string.Empty)
                {
                    string Message = Http_Request.SendErrorReport();
                    if (Message.ToLower() == "ok")
                        ClearFileContent(FilePath);
                    else
                        ErrorReport.AddError(this.ToString(), "SendErrorReport", "Error at SendErrorReport ( " + Message + " )");
                }
            }
            catch (Exception EX)
            {
                ErrorReport.AddError(this.ToString(), "SendErrorReport", EX.Message);
            }
            finally
            {
                if (streamReader != null)
                    streamReader.Close();
            }
        }
        private void CheckConnectionState()
        {
            if (InternetConnections.IsConnectedToInternet())
            {
                picbox_ConnectionState.Image = Image.FromFile(@ImagesPath + "Online.png");
            }
            else
            {
                picbox_ConnectionState.Image = Image.FromFile(@ImagesPath + "Offline.png");
            }
        }
        static string UppercaseFirst(string s)
        {
            // Check for empty string.
            if (string.IsNullOrEmpty(s))
            {
                return string.Empty;
            }
            // Return char and concat substring.
            return char.ToUpper(s[0]) + s.Substring(1);
        }
        private void CreateCheckBoxes()
        {
            XmlNodeList CheckBoxes = Initconnection.GetCategrories_CheckBoxes();
            const int Spacebetweencheckboxes = 3;
            Point Lastcheckboxlocation = checkbox_All.Location;
            Point Lastcheckboxheight = (Point)checkbox_All.Size;
            Catergory = new CheckBox[CheckBoxes.Count - 1];
            for (int i = 1; i < CheckBoxes.Count - 1; i++)
            {
                Catergory[i] = new CheckBox();
                Catergory[i].Location = new Point(Lastcheckboxlocation.X, Lastcheckboxlocation.Y + Lastcheckboxheight.Y + Spacebetweencheckboxes);
                Catergory[i].Name = "checkbox_" + CheckBoxes[i].InnerText.ToLower();
                Catergory[i].Text = UppercaseFirst(CheckBoxes[i].InnerText);
                Catergory[i].Size = new Size(100, 17);
                Catergory[i].UseVisualStyleBackColor = true;
                Lastcheckboxlocation = Catergory[i].Location;
                Lastcheckboxheight = (Point)Catergory[i].Size;
            }
            panel1.Controls.AddRange(Catergory);
        }
        private void DeleteUpdateFile()
        {
            if (File.Exists(Main.HiddenDataPath + "\\" + "WinBg.msi"))
            {
                try
                {
                    File.Delete(Main.HiddenDataPath + "\\" + "WinBg.msi");
                }
                catch (Exception EX)
                {
                    ErrorReport.AddError(this.ToString(), "DeleteUpdateFile", EX.Message);
                }
            }
        }
        #endregion

    }
}

